package com.hwz.gulimall.search.web;


import com.hwz.gulimall.search.service.MallSearchService;
import com.hwz.gulimall.search.vo.SearchParam;
import com.hwz.gulimall.search.vo.SearchResult;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: hwz
 * @CreateTime: 2025-07-16
 */

@Controller
@Slf4j
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    @GetMapping({"/", "/list.html"})
    public String index(SearchParam searchParam, Model model, HttpServletRequest request) {

        String queryString = request.getQueryString();
        searchParam.set_queryString(queryString);
        SearchResult result = mallSearchService.search(searchParam);

        model.addAttribute("result", result);
        model.addAttribute("param", searchParam);


        return "list";
    }




}
